import pytest
import requests
from api.cz_api import RechargeApi
from api.reg_login_api import RegLoginApi
from conm.uitils import assert_json
from conm.uitils import html_util,read_json


class TestRecharge(object):

    def setup(self):
        # 创建session对象
        self.ses = requests.session()
        # 实例化登录模块封装的类
        self.login = RegLoginApi(self.ses)
        # 实例化充值模块封装的类
        self.cz = RechargeApi(self.ses)
    # 获取充值验证码测试用例
    def test01_get_recharge_verify_code(self):
        # 获取充值图片验证码
        resp =  self.cz.get_recharge_verify_code(1231546)
        # 断言
        assert 200 == resp.status_code

    # 充值测试用例
    def test02_recharge(self):
        #登录
        self.login.user_login("13822138241", "qqq123")
        #获取充值图片验证码
        self.cz.get_recharge_verify_code(1231546)
        #充值
        resp=self.cz.recharge(10000)
        #断言
        assert_json(resp, 200, 200, "form")

    # 第三方充值测试用例
    def test03_third_recharge(self):
        # 登录
        self.login.user_login("13822138241", "qqq123")
        # 获取充值图片验证码
        self.cz.get_recharge_verify_code(1231546)
        # 充值
        resp = self.cz.recharge(10000)

        w = html_util(resp)
        # 获取第三方开户接口的url
        url = w[0]
        # 获取第三方开户接口的请求体数据
        body = w[1]
        # 获取第三方接口返回的响应结果
        resp1 = self.cz.third_recharge(url,body)
        #断言
        assert "OK"  in resp1.text

    # @pytest.mark.parametrize("r,exp_code",read_json("../data/recharge_data","recharge_verify_code"))
    # def test02_recharge_csh(self,r,exp_code):
    #     # 登录
    #     self.login.user_login("13822138241", "qqq123")
    #     # 获取充值图片验证码
    #     self.cz.get_recharge_verify_code(r)













